<?php
class Provincia extends CI_Controller{

    var $url ='provincia';

    function __construct(){
        parent::__construct();
        //$this->lang->load('empresa/datos');
        //$this->load->library('form_validation');
    }

    function autocomplete(){
		$term      =$this->input->post('term');
		$terme     =$this->db->escape('%'.$term.'%');
		$termed    =$this->db->escape($term.'%');
		$pais      =$this->input->post('pais');
		$paise     =$this->db->escape('%'.$pais.'%');

		$query  ="SELECT a.*, a.nombre label,c.nombre pais
				FROM provincia a
				JOIN pais c ON a.id_pais=c.id
				WHERE a.nombre LIKE $terme AND c.nombre LIKE $paise
				ORDER BY a.nombre NOT LIKE $termed,a.nombre,c.nombre ";

		$mSQL   = $this->db->query($query);
		$arreglo= $mSQL->result_array($query);

		foreach($arreglo as $key=>$value)
			foreach($value as $key2=>$value2)
				$arreglo[$key][$key2] = ($value2);

		header ('Content-type: text/html; charset=utf-8');
		echo json_encode($arreglo);
	}
}
?>
